<%@ Register TagPrefix="cc1" Namespace="PHSRAG.Insight21.InsightWebControls" Assembly="PHSRAG.Insight21.InsightWebControls" %>
<%@ Register TagPrefix="cc2" Namespace="PHSRAG.WebControls" Assembly="PHSRAG.WebControls" %>

<%@ Page Language="c#" Inherits="PHSRAG.Insight21.PersonnelDetails" CodeFile="PersonnelDetails.aspx.cs" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>PersonnelDetails</title>
    <link href="../Insight21.css" type="text/css" rel="stylesheet" />
    <style type="text/css">
		#tooltip { Z-INDEX: 200; VISIBILITY: hidden; POSITION: absolute }
		</style>
</head>
<body>
    <div id="tooltip">
    </div>

    <script type="text/javascript">
<!--

Xoffset=-60;    // modify these values to ...
Yoffset= 20;    // change the popup position.

var old,skn,iex=(document.all),yyy=-1000;

var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all

if (ns4)
    skn=document.tooltip
else if (ns6)
    skn=document.getElementById("tooltip").style
else if (ie4)
    skn=document.all.tooltip.style
if(ns4)document.captureEvents(Event.MOUSEMOVE);
else{
    skn.visibility="visible"
    skn.display="none"
}
document.onmousemove=get_mouse;

function popup(msg,bak){

var content="<table  width=150 border=1 bordercolor=black class=tooltip cellpadding=1 cellspacing=0 ><td align=center>"+msg+"</td></table>";
    yyy=Yoffset;
    if(ns4){skn.document.write(content);skn.document.close();skn.visibility="visible"}
    if(ns6){document.getElementById("tooltip").innerHTML=content;skn.display=''}
    if(ie4){document.all("tooltip").innerHTML=content;skn.display=''}
}

function get_mouse(e){
    var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
    skn.left=x+Xoffset;
    var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
    skn.top=y+yyy;
}

function kill(){
    yyy=-1000;
    if(ns4){skn.visibility="hidden";}
    else if (ns6||ie4)
    skn.display="none"
}

// The following code has been moved here from PersonnelDetails.js (obsoleted) due to
// compatibility issues where browsers other than IE could not see the included script.

//--------------------------------------------------------------------------------------------------------------------
// Show the comments by opening a pop up window
function ShowComments(location,queryString)
{
	var dialogPosition = 'width=700,height=500,scrollbars=yes,resizable=no,status=no'; 
	if(queryString != null)
	{
		location += '?' + queryString;
	}
	window.open(location,null,dialogPosition);
	return false;
}

//--------------------------------------------------------------------------------------------------------------------
// Get the number of days in a given month
function GetDaysInMonth(months)
{
	for (var i = 1; i <= months; i++) 
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) 
		{
			this[i] = 30
		}
		if (i==2) 
		{
			this[i] = 29
		}
	} 
	return this;
}

//--------------------------------------------------------------------------------------------------------------------
//Strip the delimiters from the given number/string
function StripDelimiters(number, delimiter)
{
	var returnString = "";
	for (var i = 0; i < number.length; i++)
	{   
		var c = number.charAt(i);
		if (delimiter.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

//--------------------------------------------------------------------------------------------------------------------
//Check if the date entered by the user is in the valid format "mm/dd/yyyy"
function CheckforValidDate(dateEntered)
{
	var dateDelimiter			= "/";
	var minYear					= 1;
	var maxYear					= 2100;
	var daysInMonth				= GetDaysInMonth(12);
	var delimiterFirstIndex		= dateEntered.indexOf(dateDelimiter);
	var delimiterLastIndex		= dateEntered.indexOf(dateDelimiter,delimiterFirstIndex+1);
	var monthEntered			= dateEntered.substring(0,delimiterFirstIndex);
	var dayEntered				= dateEntered.substring(delimiterFirstIndex+1,delimiterLastIndex);
	var yearEntered				= dateEntered.substring(delimiterLastIndex+1);
	var tempYear				= yearEntered;
	
	if (dayEntered.charAt(0)=="0" && dayEntered.length>1) 
		dayEntered=dayEntered.substring(1);
	if (monthEntered.charAt(0)=="0" && monthEntered.length>1) 
		monthEntered=monthEntered.substring(1);
	for (var i = 1; i <= 3; i++) 
	{
		if (tempYear.charAt(0)=="0" && tempYear.length>1) 
			tempYear=tempYear.substring(1);
	}
	month=parseInt(monthEntered);
	day=parseInt(dayEntered);
	year=parseInt(tempYear);
	
	if (delimiterFirstIndex==-1 || delimiterLastIndex==-1)
	{
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	
	if (monthEntered.length<1 || month<1 || month>12)
	{
		alert("Please enter a valid month.");
		return false;
	}

	if (yearEntered.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dateEntered.indexOf(dateDelimiter,delimiterLastIndex+1)!=-1 || CheckforValidInteger(StripDelimiters(dateEntered, dateDelimiter))==false)
	{
		alert("Please enter a valid date.");
		return false;
	}
	return true;
}

//--------------------------------------------------------------------------------------------------------------------
// Check if the given number is a valid integer
function CheckforValidInteger(number)
{
	for (var i = 0; i < number.length; i++)
	{   
		// Check that current character is number.
		var character = number.charAt(i);
		if (((character < "0") || (character > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

//--------------------------------------------------------------------------------------------------------------------
// Check if the number is a valid numeric value
function CheckforValidNumber(number)
{
	var numberValue = StripDelimiters(number,",");
	return(parseFloat(numberValue,10)==(numberValue*1));
}

//--------------------------------------------------------------------------------------------------------------------
// Validate the details entered by the user in the Annual Rate and Effective Date text boxes in the Salary adjustments grids
function ValidateSalaryAdjustment()
{
    var tableElement = window.document.getElementById('salaryGrid');
    var tableRow = tableElement.getElementsByTagName("tr");
    
    /* Doesn't work in browsers other than IE, so using method above instead.
	// get the body Element tag;
	var bodyTag = document.getElementsByTagName("body")[0];
	// get the all the elements in the table salarygrid ;
	var tableElement = bodyTag.getElementsByTagName("table").item("salaryGrid");
	// get all the 'tr' elements
	var tableRow = tableElement.getElementsByTagName("tr");*/
	
	if (!tableRow) return;
	var returnValue=true;
	for (var i=0; i<tableRow.length;i++)
	{
		// check for the tr whose class = "DataGridEditRow"
		if (tableRow.item(i).className == "DataGridEditRow")
		{
			// get the annualrate / effectivedate and do validations;
			var annualRate =tableRow.item(i).getElementsByTagName("input")[0].value;
			// if the annualrate has $ symbol, remove the same and assign the value to the annualRate.
			if ((annualRate.length > 0) && (annualRate.substring(1,0) == '$'))
					annualRate = annualRate.substring(1);
			
			if (annualRate.length == 0)
			{
				alert('Please enter the Annual Rate');
				returnValue =false;
				break;
			}
			else if (annualRate < 0)
			{
				alert('Annual Rate must be non-negative.');
				returnValue=false;
				break;
			}
			else if (annualRate >= 0 && annualRate < 1 && annualRate != 0)
			{
				alert('Annual Rate must be a dollar amount.');
				returnValue=false;
				break;
			}
			else if (!CheckforValidNumber(annualRate))
			{
				alert('Annual Rate is invalid. Please re-enter.');
				returnValue = false;
				break;
			}
			var effectiveDate = tableRow.item(i).getElementsByTagName("input")[1].value;
			if (effectiveDate == '')
			{
				alert('Please Enter the Effective Date.');
				returnValue=false;
				break;
			}
			else if (!CheckforValidDate(effectiveDate)) 
			{
				returnValue=false;
				break;
			}
		}
	}
	return returnValue;
}
//-->
//-->
    </script>

    <form id="PersonnelDetailsForm" method="post" runat="server">
        <table class="Container">
            <tr>
                <td>
                    <!-- Table 1- Header -->
                    <table class="Header">
                        <tr>
                            <td>
                                <cc1:Header ID="insightHeader" runat="server" OnNavigate="OnHeaderNavigate" />
                            </td>
                        </tr>
                    </table>
                    <!-- Table 1- Personnel Overview -->
                    <table class="overview" width="100%">
                        <tr>
                            <th>
                                &nbsp;</th>
                            <th>
                                Name:</th>
                            <th>
                                Job Code:</th>
                            <th>
                                HR Dept:</th>
                            <th>
                                Status:</th>
                            <th>
                                Title:</th>
                            <th>
                                Academic Title:</th>
                            <th>
                                Employee ID #:</th>
                            <th>
                                REC #:</th>
                            <th rowspan="2">
                                <asp:Button ID="editTitle" runat="server" CommandName="EditTitle" Width="70" CssClass="FlatButton"
                                    Text="Edit" OnClick="OnTitleEdit"></asp:Button></th>
                            <th rowspan="2">
                                <asp:Button ID="cancelTitleEdit" runat="server" CommandName="CancelEditTitle" Width="70"
                                    CssClass="FlatButton" Text="Cancel" Visible="False" OnClick="OnTitleEditCancel">
                                </asp:Button></th>
                            <th>
                                &nbsp;</th>
                        </tr>
                        <tr>
                            <td>
                            </td>
                            <td>
                                <asp:Label ID="name" runat="server"></asp:Label></td>
                            <td>
                                <asp:Label ID="jobCode" runat="server"></asp:Label></td>
                            <td>
                                <asp:Label ID="hrDepartment" runat="server"></asp:Label></td>
                            <td>
                                <asp:Label ID="status" runat="server"></asp:Label></td>
                            <td>
                                <asp:Label ID="jobTitle" runat="server"></asp:Label></td>
                            <td>
                                <asp:Label ID="harvardTitle" runat="server"></asp:Label><asp:TextBox ID="harvardTitleEntered"
                                    runat="server" Width="90" CssClass="FlatTextBox" Visible="False"></asp:TextBox></td>
                            <td>
                                <asp:Label ID="employeeId" runat="server"></asp:Label></td>
                            <td>
                                <asp:Label ID="recordNumber" runat="server"></asp:Label></td>
                            <td>
                                &nbsp;</td>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <td>
                                <cc2:BreadCrumb ID="breadCrumb" runat="server" OnNavigate="OnBreadCrumbNavigate" />
                            </td>
                        </tr>
                    </table>
                    <table cellspacing="10" class="Invisible" id="dynamicTable">
                        <tr>
                            <td>
                                <cc2:ActivityIndicator ID="activityIndicator" ContainerID="dynamicTable" runat="server">
                                </cc2:ActivityIndicator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <cc2:Annunciator ID="annunciator" ContainerID="dynamicTable" runat="server"></cc2:Annunciator>
                                <input id="hiddenSearchCriteria" runat="server" type="hidden" />
                            </td>
                        </tr>
                    </table>
                    <!-- Table 3- Bread Crumb -->
                    <table width="100%" class="PlaceBar">
                        <tr>
                            <td class="PageName">
                                &nbsp;&nbsp;Personnel Details</td>
                            <td class="PageName">
                                &nbsp;&nbsp;&nbsp;View By Fiscal Year&nbsp;
                                <asp:DropDownList ID="fiscalYear" runat="server" CssClass="FlatDropDown" AutoPostBack="True"
                                    OnSelectedIndexChanged="OnFiscalYearChanged">
                                </asp:DropDownList>
                            </td>
                            <td align="right">
                                <cc1:InsightDownloadBar ID="reportDownload" runat="server" OnFailedAction="OnDownloadFailed" />
                            </td>
                        </tr>
                    </table>
                    <!-- Table 4- Salaries-->
                    <table cellspacing="0" cellpadding="0" width="100%">
                        <tr>
                            <td>
                                <cc1:RefreshDates ID="refreshDates" runat="server" Visible="False"></cc1:RefreshDates>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table class="TitleBar" cellspacing="0" cellpadding="0" width="100%">
                                    <tr class="Title">
                                        <td>
                                            Annual Salary (Cumulative) | As of
                                            <asp:Label ID="salaryAsOfDate" runat="server"></asp:Label></td>
                                    </tr>
                                </table>
                                <asp:DataGrid ID="salaryGrid" runat="server" AutoGenerateColumns="False" CssClass="DataGrid"
                                    OnCancelCommand="OnCancel" OnEditCommand="OnSalaryEdit" OnItemCreated="OnItemCreated"
                                    OnUpdateCommand="OnSave" Width="100%">
                                    <FooterStyle CssClass="DataGridFooter"></FooterStyle>
                                    <EditItemStyle CssClass="DataGridEditRow"></EditItemStyle>
                                    <AlternatingItemStyle CssClass="DataGridAlternatingItem"></AlternatingItemStyle>
                                    <ItemStyle CssClass="DataGridItem"></ItemStyle>
                                    <HeaderStyle CssClass="DataGridHeader"></HeaderStyle>
                                    <Columns>
                                        <asp:BoundColumn DataField="AnnualRate" SortExpression="AnnualRate" HeaderText="Salary"
                                            DataFormatString="{0:c}">
                                            <ItemStyle CssClass="currency"></ItemStyle>
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="EffectiveDate" SortExpression="EffectiveDate" HeaderText="Effective Date"
                                            DataFormatString="{0:MM/dd/yyyy}"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="EditedBy" SortExpression="EditedBy" ReadOnly="True" HeaderText="Edited By">
                                        </asp:BoundColumn>
                                        <asp:BoundColumn DataField="EditDate" SortExpression="EditDate" ReadOnly="True" HeaderText="Edit Date"
                                            DataFormatString="{0:MM/dd/yyyy}"></asp:BoundColumn>
                                        <asp:TemplateColumn HeaderText="Action">
                                            <ItemTemplate>
                                                <asp:Button ID="editSalary" runat="server" CommandName="Edit" CssClass="FlatButton"
                                                    Text="Edit"></asp:Button>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:Button ID="cancelSalaryUpdate" runat="server" CommandName="Cancel" CssClass="FlatButton"
                                                    Text="Cancel"></asp:Button>
                                                <asp:Button ID="updateSalary" runat="server" CommandName="Update" CssClass="FlatButton"
                                                    Text="Update"></asp:Button>
                                            </EditItemTemplate>
                                        </asp:TemplateColumn>
                                    </Columns>
                                </asp:DataGrid>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <table width="100%">
                                    <tr>
                                        <td align="right">
                                            <asp:Button ID="addSalary" runat="server" CssClass="FlatButton" Text="Add Salary"
                                                OnClick="OnAddSalary"></asp:Button></td>
                                    </tr>
                                </table>
                                <!-- pv-->
                                <asp:Label ID="distributionWarning" runat="server"></asp:Label>
                            </td>
                        </tr>
                    </table>
                    <table class="Warnings">
                        <tr>
                            <td>
                                &nbsp;</td>
                            <td>
                                <asp:Label ID="totalErrors" runat="server"></asp:Label></td>
                        </tr>
                    </table>
                    <!-- pv-->
                    <table width="80%">
                        <tr>
                            <td>
                                <table width="100%">
                                    <tr>
                                        <td>
                                            <asp:Repeater ID="periods" runat="server" OnItemDataBound="OnPeriodsDataBound">
                                                <ItemTemplate>
                                                    <cc2:ExpandingPanel ID="expandingPanel" runat="server" ExpansionToggler="expansionToggler">
                                                        <StaticTemplate>
                                                            <table width="100%" class="PersonnelDetailsDataTitle">
                                                                <tr>
                                                                    <td style="width:100px">
                                                                        <cc2:ExpansionToggler ID="expansionToggler" runat="Server" CollapsedLinkCaption="Show Details"
                                                                            ExpandedLinkCaption="Hide Details" CollapsedImage="~/Images/Arrow_RT.gif" ExpandedImage="~/Images/Arrow_DN.gif" />
                                                                    </td>
                                                                    <td>
                                                                        &nbsp; Salary Sources:
                                                                        <asp:Label ID="salaryDate" runat="server" />
                                                                        &nbsp; Current Salary:
                                                                        <asp:Label ID="currentSalary" runat="server" /></td>
                                                                </tr>
                                                            </table>
                                                        </StaticTemplate>
                                                        <DynamicTemplate>
                                                            <table class="FlatText" width="100%">
                                                                <tr>
                                                                    <td>
                                                                        <asp:Label ID="allocationWarning" runat="server" Font-Bold="True"></asp:Label></td>
                                                                    <td>
                                                                        <asp:Label ID="effortWarning" runat="server" Font-Bold="True"></asp:Label></td>
                                                                </tr>
                                                            </table>
                                                            <table width="100%" class="DistribTitle">
                                                                <tr>
                                                                    <td>
                                                                        <asp:DataGrid ID="splits" runat="server" AutoGenerateColumns="False" CssClass="DataGrid"
                                                                            Width="100%" OnItemDataBound="OnSplitsDataBound" ShowFooter="True">
                                                                            <FooterStyle CssClass="DataGridFooter"></FooterStyle>
                                                                            <AlternatingItemStyle CssClass="DataGridAlternatingItem"></AlternatingItemStyle>
                                                                            <ItemStyle CssClass="DataGridItem"></ItemStyle>
                                                                            <HeaderStyle CssClass="DataGridHeader"></HeaderStyle>
                                                                            <Columns>
                                                                                <asp:BoundColumn HeaderText="Fund #" DataField="FundNumber" />
                                                                                <asp:BoundColumn HeaderText="Project Title" DataField="ProjectTitle" />
                                                                                <asp:BoundColumn HeaderText="Annual Rate" DataField="AnnualRate" DataFormatString="{0:c}"
                                                                                    ItemStyle-CssClass="currency" />
                                                                                <asp:BoundColumn HeaderText="Start Date" DataField="EffectiveDate" DataFormatString="{0:MM/dd/yyyy}" />
                                                                                <asp:BoundColumn HeaderText="End Date" DataField="ExpirationDate" DataFormatString="{0:MM/dd/yyyy}" />
                                                                                <asp:BoundColumn HeaderText="Effort" DataField="PercentEffort" DataFormatString="{0:n0}%" />
                                                                                <asp:BoundColumn HeaderText="To Be Paid" DataField="ToBePaid" DataFormatString="{0:c}"
                                                                                    ItemStyle-CssClass="currency" />
                                                                                <asp:BoundColumn HeaderText="Edited By" DataField="EditedBy" />
                                                                                <asp:BoundColumn HeaderText="Edit Date" DataField="EditDate" DataFormatString="{0:MM/dd/yyyy}" />
                                                                                <asp:ButtonColumn HeaderText="Comment" CommandName="SelectComment"></asp:ButtonColumn>
                                                                                <asp:TemplateColumn HeaderText="Action" HeaderStyle-Width="120">
                                                                                    <ItemTemplate>
                                                                                        <asp:Button ID="editDistribution" runat="server" CssClass="button" Text="Edit" CommandName="editDistribution"
                                                                                            Width="50" />
                                                                                        <asp:Button ID="deleteDistribution" runat="server" CssClass="button" Text="Delete"
                                                                                            CommandName="deleteDistribution" Width="50" />
                                                                                    </ItemTemplate>
                                                                                </asp:TemplateColumn>
                                                                            </Columns>
                                                                        </asp:DataGrid>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </DynamicTemplate>
                                                    </cc2:ExpandingPanel>
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                &nbsp;</td>
                                                        </tr>
                                                    </table>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                    <br />
                    <div id="commentGrid" runat="server">
                        <table cellspacing="0" cellpadding="0" width="80%">
                            <tr>
                                <td>
                                    Comment:</td>
                                <td>
                                    Username:</td>
                                <td>
                                    Edit Date:</td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:TextBox ID="comment" runat="server" CssClass="FlatTextBox" Height="100px" TextMode="MultiLine"
                                        Wrap="True" Width="500"></asp:TextBox></td>
                                <td valign="top">
                                    <asp:TextBox ID="noteEditedBy" runat="server" CssClass="FlatTextBox" Width="100"
                                        ReadOnly="True"></asp:TextBox></td>
                                <td valign="top">
                                    <asp:TextBox ID="noteEditDate" runat="server" CssClass="FlatTextBox" Width="100"
                                        ReadOnly="True"></asp:TextBox></td>
                                <td valign="top">
                                    <asp:Button ID="updateComment" runat="server" CssClass="FlatButton" Text="Update"
                                        OnClick="OnUpdateComment"></asp:Button></td>
                                <td valign="top">
                                    <asp:Button ID="addDistribution" runat="server" CssClass="FlatButtonWithoutWidth"
                                        Text="Add Distribution" Width="100"></asp:Button></td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
